package com.yunji.cabinet.device;

import com.yunji.common.exception.ServiceException;
import com.yunji.coffee.entity.dto.CoffeeInfoDTO;
import com.yunji.coffee.entity.dto.WipeDeviceInfoDTO;
import lombok.Getter;

import java.util.Objects;

@Getter
public enum ContainerTypeEnum {
    COFFEE("coffee-060", "CoffeeDeviceFacService", false, CoffeeInfoDTO.class),
    WIPE("wet-wipe-030-b", "WipeDeviceFacService", true, WipeDeviceInfoDTO.class);

    private final String typeCode;
    private final String typeService;
    private final boolean restock;
    private final Class<?> typeClass;

    ContainerTypeEnum(String typeCode, String typeService, boolean restock, Class<?> typeClass) {
        this.typeCode = typeCode;
        this.typeService = typeService;
        this.restock = restock;
        this.typeClass = typeClass;
    }

    public static ContainerTypeEnum get(String typeCode) {
        ContainerTypeEnum[] enums = ContainerTypeEnum.values();
        for (ContainerTypeEnum e : enums) {
            if (e.typeCode.equals(typeCode)) {
                return e;
            }
        }
        throw new ServiceException("");
    }

    public static boolean hasRestock(String typeCode) {
        return Objects.requireNonNull(get(typeCode)).isRestock();
    }


    public static String getService(String typeCode) {
        return Objects.requireNonNull(get(typeCode)).getTypeService();
    }

    public static <T> Class<T> getClass(String typeCode) {
        return (Class<T>) Objects.requireNonNull(get(typeCode)).getTypeClass();
    }
}
